﻿using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using GurLoader.View;

namespace GurLoader.ViewModel
{
    public class CaptureAreaViewModel
    {
        public event EventHandler RequestClose;
        public event EventHandler AreaSelected;

        public ImageSource Image { get; private set; }
        public Point SelectionStart { get; set; }
        public Point SelectionEnd { get; set; }

        public CaptureAreaViewModel(ImageSource image)
        {
            if (image == null)
                throw new ArgumentNullException("image");

            Image = image;
        }

        protected void FireAreaSelected()
        {
            if (AreaSelected != null)
                AreaSelected(this, EventArgs.Empty);
        }

        protected void FireRequestClose()
        {
            if (RequestClose != null)
                RequestClose(this, EventArgs.Empty);
        }

        public ICommand AreaSelectedCommand
        {
            get
            {
                return new DelegateCommand()
                {
                    CommandAction = () =>
                    {
                        FireAreaSelected();
                        FireRequestClose();
                    }
                };
            }
        }

        public ICommand CancelCommand
        {
            get
            {
                return new DelegateCommand()
                {
                    CommandAction = () =>
                    {
                        FireRequestClose();
                    }
                };
            }
        }
    }
}
